﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace IMCOM.Imagiality.ImageProcessing.Canvas2D.AutoContrast
{
    public class AutoContrastHandle
    {
        private Point center;

        // size of the handle in pixels
        public const int HANDLE_SIZE = 8;

        public AutoContrastHandle(Point center)
        {
            this.center = center;
        }

        public Point Move(Point mouseDelta, Point point)
        {
            return new Point(point.X + mouseDelta.X, point.Y + mouseDelta.Y);
        }

        public Cursor GetCursor()
        {
            return Cursors.SizeAll;
        }

        public void Display(Graphics graphics)
        {
            Brush handleBrush = new SolidBrush(Color.White);
            Pen handlePen = new Pen(Color.Black);

            Rectangle rectangle = new Rectangle(center.X - HANDLE_SIZE / 2, center.Y - HANDLE_SIZE / 2, HANDLE_SIZE, HANDLE_SIZE);

            graphics.FillEllipse(handleBrush, rectangle);
            graphics.DrawEllipse(handlePen, rectangle);
        }

        public bool IsWithinHandle(Point point)
        {
            Rectangle rectangle = new Rectangle(center.X - HANDLE_SIZE / 2, center.Y - HANDLE_SIZE / 2, HANDLE_SIZE, HANDLE_SIZE);

            return rectangle.Contains(point);
        }
    }
}
